﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using Diploma.Models.IRepositories;

namespace Diploma.Models.Repositories
{
    internal class OrderStatusRepository : IOrderStatusRepository
    {
        private readonly DiplomaEntities dataContext;

        public OrderStatusRepository(DiplomaEntities dataContext)
        {
            this.dataContext = dataContext;
        }

        public IEnumerable<OrderStatu> GetAll()
        {
            ObjectSet<OrderStatu> model = dataContext.OrderStatus;
            if (model.Count() == 0)
                throw new Exception("Can't find any order statuses");
            return model;
        }

        public OrderStatu GetStatus(int i)
        {
            OrderStatu status = dataContext.OrderStatus.FirstOrDefault(r => r.Value == i);
            if (status != null)
                return status;
            throw new Exception("Can't find order status number: " + i);
        }

        public OrderStatu GetStatus(Guid id)
        {
            OrderStatu status = dataContext.OrderStatus.FirstOrDefault(r => r.Id == id);
            if (status != null)
                return status;
            throw new Exception("Can't find order status Id: " + id);
        }
    }
}